/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sonatype.mavenbook.weather;

import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;


/**
 *
 * @author JHS-Home
 */
public class WeatherFormatter {
    private static Logger log = Logger.getLogger(WeatherFormatter.class);
    
    public String format(Weather weather ) throws Exception{
        log.info("Wehater formatting");
        
        Reader reader = new InputStreamReader( getClass().getClassLoader().getResourceAsStream("output.vm"));
        
        VelocityContext context = new VelocityContext();
        
        context.put("weather",weather);
        StringWriter writer = new StringWriter();
        Velocity.evaluate(context, writer, "", reader);
        return writer.toString();
    }
}
